package game.soccerField.lines;

import game.ball.SoccerBall;
import game.components.WorldSprite;

import java.awt.Color;
import java.awt.Graphics2D;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Appearance;
import com.uqbar.vainilla.appearances.Rectangle;
import com.uqbar.vainilla.colissions.CollisionDetector;

public abstract class LimitLine extends WorldSprite{


	public LimitLine(double x, double y,int width,int height) {
		super(x, y);
		this.setAppearance(new Rectangle(Color.LIGHT_GRAY,width,height));
	}
	
	@Override
	public void update(DeltaState deltaState) {
		super.update(deltaState);
		if(this.collidesAgainstBall() && !this.getScene().isAnnouncing()){
			this.getScene().setBallOnGame(false);
			this.getScene().setAnnouncing(true);
			this.execute();			
		}
	}

	public abstract void execute();

	private boolean collidesAgainstBall() {
		SoccerBall ball = this.getScene().getSoccerBall();
		Appearance app = this.getAppearance();
		return CollisionDetector.INSTANCE.collidesCircleAgainstRect(ball.getX(),ball.getY(),ball.getRatio(),
				this.getX(),this.getY(),app.getWidth(),app.getHeight());
	}
	
	@Override
	public void render(Graphics2D graphics) {
	//Para que no se dibujen las lineas
	}
	
}
